<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.12"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>emp-toolkit: /Users/wangxiao/git/emp-toolkit/emp-tool/utils/block.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="logo-full-doxygen.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">emp-toolkit
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.12 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('utils_2block_8h_source.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">block.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="utils_2block_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/*</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment">    This file is part of JustGarble.</span></div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment">    JustGarble is free software: you can redistribute it and/or modify</span></div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment">    it under the terms of the GNU General Public License as published by</span></div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment">    the Free Software Foundation, either version 3 of the License, or</span></div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment">    (at your option) any later version.</span></div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment">    JustGarble is distributed in the hope that it will be useful,</span></div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment">    but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment">    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div><div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="comment">    GNU General Public License for more details.</span></div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="comment">    You should have received a copy of the GNU General Public License</span></div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="comment">    along with JustGarble.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="comment"></span></div><div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="comment"> */</span></div><div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;</div><div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;</div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="preprocessor">#ifndef UTIL_BLOCK_H__</span></div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="preprocessor">#define UTIL_BLOCK_H__</span></div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="preprocessor">#include &lt;stdio.h&gt;</span></div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="preprocessor">#include &lt;stdlib.h&gt;</span></div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="preprocessor">#include &lt;string.h&gt;</span></div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="preprocessor">#include &lt;stdint.h&gt;</span></div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="preprocessor">#include &lt;stdbool.h&gt;</span></div><div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="preprocessor">#include &lt;xmmintrin.h&gt;</span></div><div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;<span class="preprocessor">#include &lt;emmintrin.h&gt;</span></div><div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;<span class="preprocessor">#include &lt;smmintrin.h&gt;</span></div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;<span class="preprocessor">#include &lt;wmmintrin.h&gt;</span></div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;<span class="preprocessor">#include &lt;assert.h&gt;</span></div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;</div><div class="line"><a name="l00033"></a><span class="lineno"><a class="line" href="utils_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">   33</a></span>&#160;<span class="keyword">typedef</span> __m128i <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a>;</div><div class="line"><a name="l00034"></a><span class="lineno"><a class="line" href="utils_2block_8h.html#aecd842a127367580c336c00cb62411e8">   34</a></span>&#160;<span class="keyword">typedef</span> __m128i <a class="code" href="utils_2block_8h.html#aecd842a127367580c336c00cb62411e8">block_tpl</a>[2];</div><div class="line"><a name="l00035"></a><span class="lineno"><a class="line" href="utils_2block_8h.html#a939b7dd0e7479964d6fe6984b90dd5ce">   35</a></span>&#160;<span class="keyword">inline</span> <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> <a class="code" href="utils_2block_8h.html#a939b7dd0e7479964d6fe6984b90dd5ce">xorBlocks</a>(<a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> x, <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> y){<span class="keywordflow">return</span> _mm_xor_si128(x,y);}</div><div class="line"><a name="l00036"></a><span class="lineno"><a class="line" href="utils_2block_8h.html#a26f0bc3cdba6ad8ab7e14bb989f74205">   36</a></span>&#160;<span class="keyword">inline</span> <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> <a class="code" href="utils_2block_8h.html#a26f0bc3cdba6ad8ab7e14bb989f74205">andBlocks</a>(<a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> x, <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> y){<span class="keywordflow">return</span> _mm_and_si128(x,y);}</div><div class="line"><a name="l00037"></a><span class="lineno"><a class="line" href="utils_2block_8h.html#aba00b662d58eb830061c66d369dd61f0">   37</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="utils_2block_8h.html#aba00b662d58eb830061c66d369dd61f0">xorBlocks_arr</a>(<a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a>* res, <span class="keyword">const</span> <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a>* x, <span class="keyword">const</span> <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a>* y, <span class="keywordtype">int</span> nblocks) {</div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;    <span class="keyword">const</span> <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> * dest = nblocks+x;</div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;    <span class="keywordflow">for</span> (; x != dest;) {</div><div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;        *(res++) = <a class="code" href="utils_2block_8h.html#a939b7dd0e7479964d6fe6984b90dd5ce">xorBlocks</a>(*(x++), *(y++));   </div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;    }</div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;}</div><div class="line"><a name="l00043"></a><span class="lineno"><a class="line" href="utils_2block_8h.html#a867fd60000cddc19fbf070f83ab99de3">   43</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="utils_2block_8h.html#aba00b662d58eb830061c66d369dd61f0">xorBlocks_arr</a>(<a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a>* res, <span class="keyword">const</span> <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a>* x, <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> y, <span class="keywordtype">int</span> nblocks) {</div><div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;    <span class="keyword">const</span> <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> * dest = nblocks+x;</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;    <span class="keywordflow">for</span> (; x != dest;) {</div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;        *(res++) = <a class="code" href="utils_2block_8h.html#a939b7dd0e7479964d6fe6984b90dd5ce">xorBlocks</a>(*(x++), y);    </div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    }</div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;}</div><div class="line"><a name="l00049"></a><span class="lineno"><a class="line" href="utils_2block_8h.html#abf49ccf0cdb7c2eb75660b2073bb41d3">   49</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="utils_2block_8h.html#abf49ccf0cdb7c2eb75660b2073bb41d3">xorBlocks_arr2</a>(<a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a>* res, <span class="keyword">const</span> <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a>* x, <span class="keyword">const</span> <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a>* y, <span class="keywordtype">int</span> nblocks) {</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;    <span class="keyword">const</span> <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> * dest = nblocks+x;</div><div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;    <span class="keywordflow">for</span> (; x != dest;) {</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;        *(res++) = <a class="code" href="utils_2block_8h.html#a939b7dd0e7479964d6fe6984b90dd5ce">xorBlocks</a>(*(x++), *(y++));   </div><div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;    }</div><div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;}</div><div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;</div><div class="line"><a name="l00056"></a><span class="lineno"><a class="line" href="utils_2block_8h.html#a5b8d454a7188407c793ba335cc6d38d9">   56</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="utils_2block_8h.html#a5b8d454a7188407c793ba335cc6d38d9">block_cmp</a>(<span class="keyword">const</span> <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> * x, <span class="keyword">const</span> <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> * y, <span class="keywordtype">int</span> nblocks) {</div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;    <span class="keyword">const</span> <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> * dest = nblocks+x;</div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;    <span class="keywordflow">for</span> (; x != dest;) {</div><div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;        __m128i vcmp = _mm_xor_si128(*(x++), *(y++)); </div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;        <span class="keywordflow">if</span>(!_mm_testz_si128(vcmp, vcmp))</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;            <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;    }</div><div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;    <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;}</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;</div><div class="line"><a name="l00066"></a><span class="lineno"><a class="line" href="utils_2block_8h.html#af2ad8a9f0015464df6574a13e598bdb8">   66</a></span>&#160;<span class="preprocessor">#define zero_block() _mm_setzero_si128()</span></div><div class="line"><a name="l00067"></a><span class="lineno"><a class="line" href="utils_2block_8h.html#a82cb0a8d42708a807a061856813ac9f6">   67</a></span>&#160;<span class="preprocessor">#define one_block() makeBlock(0xFFFFFFFFFFFFFFFFULL, 0xFFFFFFFFFFFFFFFFULL)</span></div><div class="line"><a name="l00068"></a><span class="lineno"><a class="line" href="utils_2block_8h.html#ad2d16c998f79ae3788be69b8e6402b00">   68</a></span>&#160;<span class="preprocessor">#define getLSB(x) (*((unsigned short *)&amp;x)&amp;1)</span></div><div class="line"><a name="l00069"></a><span class="lineno"><a class="line" href="utils_2block_8h.html#a371865208357f993ac4e691d54bd806d">   69</a></span>&#160;<span class="preprocessor">#define makeBlock(X,Y) _mm_set_epi64((__m64)(X), (__m64)(Y))</span></div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;</div><div class="line"><a name="l00071"></a><span class="lineno"><a class="line" href="utils_2block_8h.html#a5d6a5bd7b77a4610c6158487adbe5ba4">   71</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="utils_2block_8h.html#a5d6a5bd7b77a4610c6158487adbe5ba4">isZero</a>(<span class="keyword">const</span> <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> * b) {</div><div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;    <span class="keywordflow">return</span> _mm_testz_si128(*b,*b);</div><div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;}</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;</div><div class="line"><a name="l00075"></a><span class="lineno"><a class="line" href="utils_2block_8h.html#a01d7fb04c12a2a0e2e30c31e0c61d44d">   75</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="utils_2block_8h.html#a01d7fb04c12a2a0e2e30c31e0c61d44d">isOne</a>(<span class="keyword">const</span> <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> * b) {</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;    __m128i neq = _mm_xor_si128(*b, <a class="code" href="utils_2block_8h.html#a82cb0a8d42708a807a061856813ac9f6">one_block</a>());</div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;    <span class="keywordflow">return</span> _mm_testz_si128(neq, neq);</div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;}</div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;</div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;</div><div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;<span class="comment">//Modified from</span></div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;<span class="comment">//https://mischasan.wordpress.com/2011/10/03/the-full-sse2-bit-matrix-transpose-routine/</span></div><div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;<span class="comment">// with inner most loops changed to _mm_set_epi8 and _mm_set_epi16</span></div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;    <span class="keyword">inline</span> <span class="keywordtype">void</span></div><div class="line"><a name="l00085"></a><span class="lineno"><a class="line" href="utils_2block_8h.html#a7f0914003ef8a598677701815879c834">   85</a></span>&#160;<a class="code" href="utils_2block_8h.html#a7f0914003ef8a598677701815879c834">sse_trans</a>(uint8_t *out, uint8_t <span class="keyword">const</span> *inp, <span class="keywordtype">int</span> nrows, <span class="keywordtype">int</span> ncols)</div><div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;{</div><div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;<span class="preprocessor">#   define INP(x,y) inp[(x)*ncols/8 + (y)/8]</span></div><div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;<span class="preprocessor">#   define OUT(x,y) out[(y)*nrows/8 + (x)/8]</span></div><div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;    <span class="keywordtype">int</span> rr, cc, i, h;</div><div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;    <span class="keyword">union </span>{ __m128i x; uint8_t b[16]; } tmp;</div><div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;    __m128i vec;</div><div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;    assert(nrows % 8 == 0 &amp;&amp; ncols % 8 == 0);</div><div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;</div><div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;    <span class="comment">// Do the main body in 16x8 blocks:</span></div><div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;    <span class="keywordflow">for</span> (rr = 0; rr &lt;= nrows - 16; rr += 16) {</div><div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;        <span class="keywordflow">for</span> (cc = 0; cc &lt; ncols; cc += 8) {</div><div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;            vec = _mm_set_epi8(</div><div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;                    <a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr+15,cc),<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr+14,cc),<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr+13,cc),<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr+12,cc),<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr+11,cc),<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr+10,cc),<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr+9,cc),</div><div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;                    <a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr+8,cc),<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr+7,cc),<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr+6,cc),<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr+5,cc),<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr+4,cc),<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr+3,cc),<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr+2,cc),<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr+1,cc),</div><div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;                    <a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr+0,cc));</div><div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;            <span class="keywordflow">for</span> (i = 8; --i &gt;= 0; vec = _mm_slli_epi64(vec, 1))</div><div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;                *(uint16_t*)&amp;<a class="code" href="utils_2block_8h.html#af0f79f5377461c33c6505836d07ba456">OUT</a>(rr,cc+i)= _mm_movemask_epi8(vec);</div><div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;        }</div><div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;    }</div><div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;    <span class="keywordflow">if</span> (rr == nrows) <span class="keywordflow">return</span>;</div><div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;</div><div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;    <span class="comment">// The remainder is a block of 8x(16n+8) bits (n may be 0).</span></div><div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;    <span class="comment">//  Do a PAIR of 8x8 blocks in each step:</span></div><div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;    <span class="keywordflow">for</span> (cc = 0; cc &lt;= ncols - 16; cc += 16) {</div><div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;        vec = _mm_set_epi16(</div><div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;                *(uint16_t <span class="keyword">const</span>*)&amp;<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr + 7, cc), *(uint16_t <span class="keyword">const</span>*)&amp;<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr + 6, cc),</div><div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;                *(uint16_t <span class="keyword">const</span>*)&amp;<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr + 5, cc), *(uint16_t <span class="keyword">const</span>*)&amp;<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr + 4, cc),</div><div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;                *(uint16_t <span class="keyword">const</span>*)&amp;<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr + 3, cc), *(uint16_t <span class="keyword">const</span>*)&amp;<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr + 2, cc),</div><div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;                *(uint16_t <span class="keyword">const</span>*)&amp;<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr + 1, cc), *(uint16_t <span class="keyword">const</span>*)&amp;<a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr + 0, cc));</div><div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;        <span class="keywordflow">for</span> (i = 8; --i &gt;= 0; vec = _mm_slli_epi64(vec, 1)) {</div><div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;            <a class="code" href="utils_2block_8h.html#af0f79f5377461c33c6505836d07ba456">OUT</a>(rr, cc + i) = h = _mm_movemask_epi8(vec);</div><div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;            <a class="code" href="utils_2block_8h.html#af0f79f5377461c33c6505836d07ba456">OUT</a>(rr, cc + i + 8) = h &gt;&gt; 8;</div><div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;        }</div><div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;    }</div><div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;    <span class="keywordflow">if</span> (cc == ncols) <span class="keywordflow">return</span>;</div><div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;</div><div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;    <span class="comment">//  Do the remaining 8x8 block:</span></div><div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;    <span class="keywordflow">for</span> (i = 0; i &lt; 8; ++i)</div><div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;        tmp.b[i] = <a class="code" href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a>(rr + i, cc);</div><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;    <span class="keywordflow">for</span> (i = 8; --i &gt;= 0; tmp.x = _mm_slli_epi64(tmp.x, 1))</div><div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;        <a class="code" href="utils_2block_8h.html#af0f79f5377461c33c6505836d07ba456">OUT</a>(rr, cc + i) = _mm_movemask_epi8(tmp.x);</div><div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;}</div><div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;</div><div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;</div><div class="line"><a name="l00130"></a><span class="lineno"><a class="line" href="utils_2block_8h.html#a1a61c940fcdfab9d717ed2f9c27f3602">  130</a></span>&#160;<span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="utils_2block_8h.html#a1a61c940fcdfab9d717ed2f9c27f3602">fix_key</a>[] = <span class="stringliteral">&quot;\x61\x7e\x8d\xa2\xa0\x51\x1e\x96&quot;</span></div><div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;<span class="stringliteral">&quot;\x5e\x41\xc2\x9b\x15\x3f\xc7\x7a&quot;</span>;</div><div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;</div><div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;<span class="comment">/*------------------------------------------------------------------------</span></div><div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;<span class="comment">  / OCB Version 3 Reference Code (Optimized C)     Last modified 08-SEP-2012</span></div><div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;<span class="comment">  /-------------------------------------------------------------------------</span></div><div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;<span class="comment">  / Copyright (c) 2012 Ted Krovetz.</span></div><div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;<span class="comment">  /</span></div><div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;<span class="comment">  / Permission to use, copy, modify, and/or distribute this software for any</span></div><div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;<span class="comment">  / purpose with or without fee is hereby granted, provided that the above</span></div><div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;<span class="comment">  / copyright notice and this permission notice appear in all copies.</span></div><div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;<span class="comment">  /</span></div><div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;<span class="comment">  / THE SOFTWARE IS PROVIDED &quot;AS IS&quot; AND THE AUTHOR DISCLAIMS ALL WARRANTIES</span></div><div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;<span class="comment">  / WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF</span></div><div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;<span class="comment">  / MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR</span></div><div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;<span class="comment">  / ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES</span></div><div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;<span class="comment">  / WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN</span></div><div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;<span class="comment">  / ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF</span></div><div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;<span class="comment">  / OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.</span></div><div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;<span class="comment">  /</span></div><div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;<span class="comment">  / Phillip Rogaway holds patents relevant to OCB. See the following for</span></div><div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;<span class="comment">  / his patent grant: http://www.cs.ucdavis.edu/~rogaway/ocb/grant.htm</span></div><div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;<span class="comment">  /</span></div><div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;<span class="comment">  / Special thanks to Keegan McAllister for suggesting several good improvements</span></div><div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;<span class="comment">  /</span></div><div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;<span class="comment">  / Comments are welcome: Ted Krovetz &lt;ted@krovetz.net&gt; - Dedicated to Laurel K</span></div><div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;<span class="comment">  /------------------------------------------------------------------------- */</span></div><div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;<span class="keyword">static</span> <span class="keyword">inline</span> <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> double_block(<a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> bl) {</div><div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;    <span class="keyword">const</span> __m128i mask = _mm_set_epi32(135,1,1,1);</div><div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;    __m128i tmp = _mm_srai_epi32(bl, 31);</div><div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;    tmp = _mm_and_si128(tmp, mask);</div><div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;    tmp = _mm_shuffle_epi32(tmp, _MM_SHUFFLE(2,1,0,3));</div><div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;    bl = _mm_slli_epi32(bl, 1);</div><div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;    <span class="keywordflow">return</span> _mm_xor_si128(bl,tmp);</div><div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;}</div><div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;</div><div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;<span class="keyword">static</span> <span class="keyword">inline</span> <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> LEFTSHIFT1(<a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> bl) {</div><div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;    <span class="keyword">const</span> __m128i mask = _mm_set_epi32(0,0, (1&lt;&lt;31),0);</div><div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;    __m128i tmp = _mm_and_si128(bl,mask);</div><div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;    bl = _mm_slli_epi64(bl, 1);</div><div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;    <span class="keywordflow">return</span> _mm_xor_si128(bl,tmp);</div><div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;}</div><div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;<span class="keyword">static</span> <span class="keyword">inline</span> <a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> RIGHTSHIFT(<a class="code" href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a> bl) {</div><div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;    <span class="keyword">const</span> __m128i mask = _mm_set_epi32(0,1,0,0);</div><div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;    __m128i tmp = _mm_and_si128(bl,mask);</div><div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;    bl = _mm_slli_epi64(bl, 1);</div><div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;    <span class="keywordflow">return</span> _mm_xor_si128(bl,tmp);</div><div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;}</div><div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;<span class="preprocessor">#endif//UTIL_BLOCK_H__</span></div><div class="ttc" id="garble_2block_8h_html_a65abbf31b0a30290189cdb5059b5f785"><div class="ttname"><a href="garble_2block_8h.html#a65abbf31b0a30290189cdb5059b5f785">block</a></div><div class="ttdeci">__m128i block</div><div class="ttdef"><b>Definition:</b> block.h:8</div></div>
<div class="ttc" id="utils_2block_8h_html_a5d6a5bd7b77a4610c6158487adbe5ba4"><div class="ttname"><a href="utils_2block_8h.html#a5d6a5bd7b77a4610c6158487adbe5ba4">isZero</a></div><div class="ttdeci">bool isZero(const block *b)</div><div class="ttdef"><b>Definition:</b> block.h:71</div></div>
<div class="ttc" id="utils_2block_8h_html_a939b7dd0e7479964d6fe6984b90dd5ce"><div class="ttname"><a href="utils_2block_8h.html#a939b7dd0e7479964d6fe6984b90dd5ce">xorBlocks</a></div><div class="ttdeci">block xorBlocks(block x, block y)</div><div class="ttdef"><b>Definition:</b> block.h:35</div></div>
<div class="ttc" id="utils_2block_8h_html_aecd842a127367580c336c00cb62411e8"><div class="ttname"><a href="utils_2block_8h.html#aecd842a127367580c336c00cb62411e8">block_tpl</a></div><div class="ttdeci">__m128i block_tpl[2]</div><div class="ttdef"><b>Definition:</b> block.h:34</div></div>
<div class="ttc" id="utils_2block_8h_html_a01d7fb04c12a2a0e2e30c31e0c61d44d"><div class="ttname"><a href="utils_2block_8h.html#a01d7fb04c12a2a0e2e30c31e0c61d44d">isOne</a></div><div class="ttdeci">bool isOne(const block *b)</div><div class="ttdef"><b>Definition:</b> block.h:75</div></div>
<div class="ttc" id="utils_2block_8h_html_a7f0914003ef8a598677701815879c834"><div class="ttname"><a href="utils_2block_8h.html#a7f0914003ef8a598677701815879c834">sse_trans</a></div><div class="ttdeci">void sse_trans(uint8_t *out, uint8_t const *inp, int nrows, int ncols)</div><div class="ttdef"><b>Definition:</b> block.h:85</div></div>
<div class="ttc" id="utils_2block_8h_html_abf49ccf0cdb7c2eb75660b2073bb41d3"><div class="ttname"><a href="utils_2block_8h.html#abf49ccf0cdb7c2eb75660b2073bb41d3">xorBlocks_arr2</a></div><div class="ttdeci">void xorBlocks_arr2(block *res, const block *x, const block *y, int nblocks)</div><div class="ttdef"><b>Definition:</b> block.h:49</div></div>
<div class="ttc" id="utils_2block_8h_html_a1a61c940fcdfab9d717ed2f9c27f3602"><div class="ttname"><a href="utils_2block_8h.html#a1a61c940fcdfab9d717ed2f9c27f3602">fix_key</a></div><div class="ttdeci">const char fix_key[]</div><div class="ttdef"><b>Definition:</b> block.h:130</div></div>
<div class="ttc" id="utils_2block_8h_html_af0f79f5377461c33c6505836d07ba456"><div class="ttname"><a href="utils_2block_8h.html#af0f79f5377461c33c6505836d07ba456">OUT</a></div><div class="ttdeci">#define OUT(x, y)</div></div>
<div class="ttc" id="utils_2block_8h_html_a5b8d454a7188407c793ba335cc6d38d9"><div class="ttname"><a href="utils_2block_8h.html#a5b8d454a7188407c793ba335cc6d38d9">block_cmp</a></div><div class="ttdeci">bool block_cmp(const block *x, const block *y, int nblocks)</div><div class="ttdef"><b>Definition:</b> block.h:56</div></div>
<div class="ttc" id="utils_2block_8h_html_a82cb0a8d42708a807a061856813ac9f6"><div class="ttname"><a href="utils_2block_8h.html#a82cb0a8d42708a807a061856813ac9f6">one_block</a></div><div class="ttdeci">#define one_block()</div><div class="ttdef"><b>Definition:</b> block.h:67</div></div>
<div class="ttc" id="utils_2block_8h_html_ad8a4fc15f304728d30cc637008591520"><div class="ttname"><a href="utils_2block_8h.html#ad8a4fc15f304728d30cc637008591520">INP</a></div><div class="ttdeci">#define INP(x, y)</div></div>
<div class="ttc" id="utils_2block_8h_html_aba00b662d58eb830061c66d369dd61f0"><div class="ttname"><a href="utils_2block_8h.html#aba00b662d58eb830061c66d369dd61f0">xorBlocks_arr</a></div><div class="ttdeci">void xorBlocks_arr(block *res, const block *x, const block *y, int nblocks)</div><div class="ttdef"><b>Definition:</b> block.h:37</div></div>
<div class="ttc" id="utils_2block_8h_html_a26f0bc3cdba6ad8ab7e14bb989f74205"><div class="ttname"><a href="utils_2block_8h.html#a26f0bc3cdba6ad8ab7e14bb989f74205">andBlocks</a></div><div class="ttdeci">block andBlocks(block x, block y)</div><div class="ttdef"><b>Definition:</b> block.h:36</div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_eec959d81771dc8b1a750b834e1341eb.html">emp-tool</a></li><li class="navelem"><a class="el" href="dir_363cbed62d1567d90b8cbb6bda69428f.html">utils</a></li><li class="navelem"><a class="el" href="utils_2block_8h.html">block.h</a></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.12 </li>
  </ul>
</div>
</body>
</html>
